package com.flyduck.mall.pms.dubbo;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.flyduck.mall.common.core.utils.BeanUtils;
import com.flyduck.mall.pms.api.RemoteProductService;
import com.flyduck.mall.pms.domain.PmsProduct;
import com.flyduck.mall.pms.mapper.PmsProductMapper;
import com.flyduck.mall.pms.api.vo.RemoteProductRespVO;
import com.flyduck.mall.pms.api.vo.RemoteProductUpdateReqVO;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @program: vueshop-cloud
 * @description:
 * @author: flyduck
 * @create: 2024-07-15 21:14
 **/
@DubboService
public class RemoteProductServiceImpl implements RemoteProductService {

    @Resource
    private PmsProductMapper pmsProductMapper;

    @Override
    public RemoteProductRespVO getProductById(Long id) {
        PmsProduct pmsProduct = pmsProductMapper.selectById(id);
        RemoteProductRespVO remoteProductRespVO = BeanUtils.toBean(pmsProduct, RemoteProductRespVO.class);
        return remoteProductRespVO;
    }

    @Override
    public List<RemoteProductRespVO> getOnSaleProductList() {
        List<PmsProduct> pmsProductList = pmsProductMapper.selectList(
                new LambdaQueryWrapper<PmsProduct>()
                        .eq(PmsProduct::getIsOnSale, true)
        );
        return BeanUtils.toBeanList(pmsProductList,RemoteProductRespVO.class);
    }

    @Override
    public void batchUpdateProduct(List<RemoteProductUpdateReqVO> remoteProductUpdateReqVOList) {
        List<PmsProduct> pmsProductList = BeanUtils.toBeanList(remoteProductUpdateReqVOList, PmsProduct.class);
        pmsProductMapper.insertOrUpdate(pmsProductList);
    }
}
